﻿/*
 * 2008 (c) ralfoide at gmail com
 * Project: SharpFlow
 * License: GPL
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Alfray.SharpFlow.Core;
using System.Drawing;

namespace Alfray.SharpFlow.Utils {
    /// <summary>
    /// Specialized form that can save its position into the preferences
    /// and restore it automatically.
    /// </summary>
    public class AutoSavingForm : Form {

        /// <summary>
        /// Load the window position, if it exists in the preferences.
        /// 
        /// This does not actually load preferences from disk.
        /// </summary>
        public void loadWindowPosition() {
            // load position & size of this window
            Rectangle r;
            if (DataCore.singleton.preferences.getRect(GetType().FullName, out r)) {
                this.Bounds = r;
                // tell Windows not to change this position, to avoid overriding the
                // one we just set.
                this.StartPosition = FormStartPosition.Manual;
            }
        }

        /// <summary>
        /// Save position & size of this window into the preferences.
        /// 
        /// This does not actually save the preferences to disk.
        /// </summary>
        public void saveWindowPosition() {
            DataCore.singleton.preferences.setRect(GetType().FullName, this.Bounds);
        }
    }
}
